<style type="text/css" media="screen">
.f-cb{
    zoom: 1;
}
.f-cb:after{
    display:block;
    height:0;
    clear:both;
    visibility:hidden;
    overflow:hidden;
    content:".";
}
.dn{
	display: none;
}
.toufqy .fl{
	float: left;
}
.topfqy .fr{
	float: right;
}
.toufqy dt{
	font-size: 14px;
	font-weight: bold;
	width: 100px;
	padding-right: 10px;
	text-align: right;
}
.toufqy .label{
	display: inline-block;
	margin-right: 50px;
}
.toufqy .label span{
	display: inline-block;
	margin-left: 5px;
	vertical-align: top;
}
.toufqy .province{
	padding-top: 10px;
	overflow: hidden;
}
.toufqy .province .left{
	width: 140px;
	height: 208px;
	background: #fff;
	border:1px solid #e7e7e7;
	overflow: auto;
}
.toufqy .province p{
	padding-left: 15px;
	line-height: 26px;
	cursor: pointer;
}
.toufqy .province p:hover{
	background-color: #f5f5f5;
}
.toufqy .province .right{
	margin-left: 26px;
	width: 142px;
	background: #fff;
}
.toufqy .province .right p:hover{
	background: #f5f5f5 url(../../../../static/m/img/task_01.png) no-repeat 110px center;
}
.toufqy .province .right .top{
	background: #479eff;
	line-height: 26px;
	color: #fff;
	text-align: center;
}
.toufqy .province .right .txt{
	border:1px solid #e7e7e7;
	border-top: 0;
	overflow: auto;
	height: 183px;
}
.toufqy .age{
	padding-top: 10px;
}
.toufqy .age label{
	background: #fff;
	display: block;
	padding:0 5px;
	border:1px solid #e7e7e7;
	float: left;
}
.toufqy .age .ts{
	width: 18px;
	height: 1px;
	background: #a8a8a8;
	color: #a8a8a8;
	display: block;
	margin:15px 7px 0;
	float: left;
}
.toufqy .age .text{
	padding:5px 0;
	width: 70px;
	border:0;
}
.toufqy .edu{
	background: #fff;
	border:1px solid #e7e7e7;
	margin-top: 10px;
	padding:6px 0;
	width: 398px;
}
.toufqy .edu label{
	display: block;
	float: left;
	margin:7px 32px 7px 25px;
}
.toufqy .edu label span{
	margin-left: 5px;
}
.toufqy .ind{
	background: #fff;
	border:1px solid #e7e7e7;
	margin-top: 10px;
	padding:6px 0;
	width: 398px;
}
.toufqy .ind label{
	display: block;
	float: left;
	margin:7px 0 7px 25px;
	width: 172px;
}
.toufqy .ind label span{
	margin-left: 5px;
}
.toufqy .money{
	background: #fff;
	border:1px solid #e7e7e7;
	margin-top: 10px;
	padding:6px 0;
	width: 398px;
}
.toufqy .money label{
	display: block;
	float: left;
	margin:7px 0 7px 25px;
	width: 107px;
}
.toufqy .money label span{
	margin-left: 5px;
}
</style>
			<!-- 任务定向信息 -->
			<h3>定向条件</h3>
			<div class="toufqy">

                <!-- 投放区域 -->
                <?php 
                    $place_arr = array();
                    $places    = array();
                    if (isset($it['placeid']) and $it['placeid']){
                        $places = explode(',', $it['placeid']); 
                    } else {
                        $it['placeid'] = '';
                    }
                ?>
    			<dl class="f-cb">
    				<dt class="fl">投放区域：</dt>
    				<dd class="fl">
    					<div class="select">
    						<label class="label"><input type="radio" value="0" <?php echo $it['placeid'] ? '' : 'checked'; ?>><span>不限</span></label>
    						<label class="label"><input type="radio" value="1" <?php echo !$it['placeid'] ? '' : 'checked'; ?>><span>省／直辖市</span></label>
    					</div>
    					<div class="scon province f-cb <?php echo $it['placeid'] ? '' : 'dn'; ?>">
    						<div class="left fl">
                            <?php if ($provinces = get_province()): ?>
                                <?php foreach ($provinces as $p): ?>
                                    <?php  
                                        if($places and in_array($p['id'], $places)) {
                                            array_push($place_arr, $p);
                                            continue;
                                        } 
                                    ?>
                                <p data-id='<?php echo $p['id'] ?>'><?php echo $p['title'] ?></p>                            
                                <?php endforeach ?>                                
                            <?php endif ?>
    						</div>
    						<div class="right fl">
    							<div class="top">已填加<?php echo isset($places) ? count($places) : 0; ?>个省份</div>
    							<div class="txt">
                                    <?php foreach ($place_arr as $p): ?>
                                    <p data-id='<?php echo $p['id'] ?>'><?php echo $p['title'] ?></p>                         
                                    <?php endforeach ?>                     
                                </div>
    						</div>
    					</div>
    				</dd>
    			</dl>
                <input id="placeid" type="hidden" name="placeid" value="<?php echo set_value('placeid', $it['placeid']) ?>">

                <!-- 用户年龄 -->
    			<dl class="f-cb">
    				<dt class="fl">用户年龄：</dt>
    				<dd class="fl">
    					<div class="select">
    						<label class="label"><input type="radio"  value="0" <?php echo !isset($it['min_age']) ? 'checked' : ''; ?>><span>不限</span></label>
    						<label class="label"><input type="radio"  value="1" <?php echo isset($it['min_age']) ? 'checked' : ''; ?>><span>年龄范围</span></label>
    					</div>
    					<div class="scon age f-cb <?php echo isset($it['min_age']) ? '' : 'dn'; ?>">
    						<label><input type="text" class="text" id="min_age" name="min_age" value="<?php echo isset($it['min_age']) ? $it['min_age'] : ''; ?>"><span>岁</span></label>
                            <span class="ts">&nbsp;</span>
                            <label><input type="text" class="text" id="max_age" name="max_age" value="<?php echo isset($it['max_age']) ? $it['max_age'] : ''; ?>"><span>岁</span></label>
    					</div>
    				</dd>
    			</dl>

                <!-- 用户性别 -->
    			<dl class="f-cb">
    				<dt class="fl">用户性别：</dt>
    				<dd class="fl">
    					<div>
    						<label class="label"><input type="radio" name="sex" value="0" <?php echo isset($it['sex']) and $it['sex'] == 0 ? 'checked' : ''; ?>><span>不限</span></label>
    						<label class="label"><input type="radio" name="sex" value="1" <?php echo isset($it['sex']) and $it['sex'] == 1 ? 'checked' : ''; ?>><span>男</span></label>
    						<label class="label"><input type="radio" name="sex" value="2" <?php echo isset($it['sex']) and $it['sex'] == 2 ? 'checked' : ''; ?>><span>女</span></label>
    					</div>
    				</dd>
    			</dl>

                <!-- 自定义定向 -->
                <?php 
                    $account_spc = array();
                    $spcids      = array();
                    if (isset($it['spcids']) and $it['spcids']){
                        $spcids_tmp = explode(';', $it['spcids']); 
                        foreach ($spcids_tmp as $tmp) {
                            $spcid = explode(':', $tmp);
                            if (isset($spcid[1])) {
                                $spcids[$spcid[0]] = explode(',', $spcid[1]);
                            }
                        }
                    } else {
                        $it['spcids'] = '';
                    }
                    $types = list_coltypes(5,0,'ctype');
                ?>
                <?php foreach ($types as $t): ?>
                    <?php foreach ($t['more'] as $m): ?>
                    <?php $list = get_account_spc($m['id']) ?>
                    <dl class="f-cb account_spc" data-id="<?php echo $m['id'] ?>">
                        <dt class="fl"><?php echo $m['title'] ?>：</dt>
                        <dd class="fl">
                            <div class="select">
                                <label class="label"><input type="radio" value="0" <?php echo isset($spcids[$m['id']]) ? '' : 'checked'; ?>><span>不限</span></label>
                                <label class="label"><input type="radio" value="1" <?php echo !isset($spcids[$m['id']]) ? '' : 'checked'; ?>><span>自定义</span></label>
                            </div>
                            <div class="scon edu f-cb <?php echo isset($spcids[$m['id']]) ? '' : 'dn'; ?>">
                            <?php foreach ($list as $l): ?>
                                <label>
                                    <input type="checkbox" class="checkbox apc" <?php echo (isset($spcids[$m['id']]) and in_array($l['id'], $spcids[$m['id']])) ? 'checked' : ''; ?> data-id="<?php echo $l['id'] ?>">
                                    <span><?php echo $l['title'] ?></span>
                                </label>
                            <?php endforeach ?>
                            </div>
                        </dd>
                    </dl>    
                    <?php endforeach ?>    
                <?php endforeach ?>
                <input id="spcids" type="hidden" name="spcids" value="<?php echo set_value('spcids', $it['spcids']) ?>">
    		</div>
<script type="text/javascript">
require(['jquery'],function($){

    $("input:radio").click(function(){
        var parent = $(this).parent().parent('.select');

        if ($(this).val() == 1) {

            parent.find('input:radio[value=0]').removeAttr('checked')
            $(parent).next().removeClass("dn");
        } else {

            parent.find('input:radio[value=1]').removeAttr('checked')
            $(parent).next().addClass("dn");
        }
    });

    // 省份添加/减少
    $(".province .fl").delegate("p",'click',function(){
        var _this = $(this);
        var _html = $(this).html();
        if (_this.parent('div').eq(0).hasClass('txt')) {
            $(".province .left").prepend("<p data-id='"+_this.data('id')+"''>"+_html+"</p>");
        } else {
            $(".province .right .txt").prepend("<p data-id='"+_this.data('id')+"''>"+_html+"</p>");
        };
        _this.remove();
        var placeids = '';
        var count = 0;
        $(".province .right p").each(function(){

            placeids += ',' + $(this).data('id');
            count++;
        })
        if (placeids) {
            placeids = placeids.substr(1);
        };
        $(".right .top").html("已添加个"+count+"省份");
        $("#placeid").val(placeids);
    })

    // 年龄设置
    $("input.apc").click(function(){
        var spcids = '';
        $(".account_spc").each(function(i,e){
            spcids += i ? ';'+$(e).data('id') : $(e).data('id');
            var k = 0;
            $(e).find('input.apc').each(function(j,ee){

                if (ee.checked) {
                    spcids += k ? ','+$(ee).data('id') : ':' + $(ee).data('id');
                    k++;
                };
                
            })
        })
        $("#spcids").val(spcids);
    });

});
</script>